<template>
  <popup class="index-popup" :is-show="$store.state.isShowPagePopup">
    <div class="index-create-pro" slot="main">
      <div class="popup-btn" @click="$store.commit('changePagePopupStatus')">×</div>
      <div class="index-popup-a">添加页面</div>
      <div class="index-popup-b">
        <input placeholder="请输入项目名..." v-model="newPageName"/>
        <input placeholder="请输入简介..." v-model="newPageDesc"/>
        <br>
        <div class="index-pro" @click="createPage">添加</div>
      </div>
    </div>
  </popup>
</template>

<script>
  import Popup from '../common/popup'

  const PageApi = require('../../services/PageService');

  export default {
    name: "index-page-popup",
    components: {
      Popup
    },
    props: {
      isShow: false
    },
    data() {
      return {
        newPageName: "",
        newPageDesc: ""
      }
    },
    created() {
    },
    methods: {
      createPage: async function () {
        let resp = await PageApi.savePageData({
          "name": this.newPageName,
          "desc": this.newPageDesc,
        });
        if (resp && resp.successful === 1) {
          let response = await PageApi.getPageData()
          if (response && response.data.length > 0) {
            this.$store.state.treeData = response.data
          }
        }
        this.$store.commit('changePagePopupStatus');
      },
    }
  }
</script>
<style scoped>
  .index-popup {
    position: absolute;
    display: flex;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: center;
    z-index: 400;
  }

  .index-create-pro {
    display: block;
    width: 400px;
    height: 400px;
    border-radius: 8px;
  }

  .popup-btn {
    position: absolute;
    right: 10px;
    top: 10px;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    user-select: none;
    cursor: pointer;
    font-size: 20px;
    font-weight: bolder;
    /*background-color: darkgray;*/
    color: #ffffff;
  }

  .index-popup-a {
    display: flex;
    width: 400px;
    height: 200px;
    color: #ffffff;
    font-size: 30px;
    justify-content: center;
    align-items: center;
    background-color: rgb(116, 62, 234);
    border-radius: 15px 15px 0px 0px;
    user-select: none;
  }

  .index-popup-b {
    display: block;
    width: 400px;
    height: 200px;
    padding-top: 40px;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    border-radius: 0px 0px 15px 15px;
  }

  .index-create-pro input {
    /*display: block;*/
    width: 65%;
    outline: none;
    background-color: #f3f3f3;
    border: none;
    height: 40px;
    margin: 10px;
    border-radius: 4px;
    padding-left: 10px;
    align-self: center;
    color: #333333;
    font-size: 15px;
    letter-spacing: 1px;
  }

  .index-pro {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    height: 40px;
    width: 120px;
    margin: 10px 10px 0px 10px;
    cursor: pointer;
    border-radius: 15px;
    color: #ffffff;
    user-select: none;
    background-color: rgba(116, 62, 234, 0.8)
  }
</style>
